home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / softwareproperties / gtk / DialogAptKey.py < prev    next >
Encoding:
Python Source  |  2009-03-27  |  4.1 KB  |  120 lines

  1. # dialog_apt_key.py.in - edit the apt keys
  2. #  
  3. #  Copyright (c) 2004 Canonical
  4. #  
  5. #  Author: Michael Vogt <mvo@debian.org>
  6. #  This program is free software; you can redistribute it and/or 
  7. #  modify it under the terms of the GNU General Public License as 
  8. #  published by the Free Software Foundation; either version 2 of the
  9. #  License, or (at your option) any later version.
  10. #  This program is distributed in the hope that it will be useful,
  11. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #  GNU General Public License for more details.
  14. #  You should have received a copy of the GNU General Public License
  15. #  along with this program; if not, write to the Free Software
  16. #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. #  USA
  18.  
  19. import os
  20. import gobject
  21. import gtk
  22. import gtk.glade
  23. import subprocess
  24. import gettext
  25. from utils import *
  26. from subprocess import PIPE
  27.  
  28. # gettext convenient
  29. _ = gettext.gettext
  30. def dummy(e): return e
  31. N_ = dummy
  32.  
  33. # some known keys
  34. N_("Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>")
  35. N_("Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>")
  36.  
  37. class DialogAddKey:
  38.   """This class is currently not used anymore"""
  39.   def __init__(self, parent, datadir):
  40.     # gtk stuff
  41.     if os.path.exists("../data/dialogs.glade"):
  42.       self.gladexml = gtk.glade.XML("../data/dialogs.glade")
  43.     else:
  44.       self.gladexml = gtk.glade.XML("%s/dialogs.glade", datadir)
  45.     self.main = self.gladexml.get_widget("dialog_apt_key")
  46.     self.main.set_transient_for(parent)
  47.  
  48.     self.gladexml.signal_connect("on_button_key_add_clicked",
  49.                                  self.on_button_key_add_clicked)
  50.     self.gladexml.signal_connect("on_button_key_remove_clicked",
  51.                                  self.on_button_key_remove_clicked)
  52.     self.gladexml.signal_connect("on_button_apt_key_update_clicked",
  53.                                  self.on_button_apt_key_update_clicked)
  54.  
  55.     # create apt-key object (abstraction for the apt-key command)
  56.     self.apt_key = apt_key()
  57.     
  58.     # get some widgets
  59.     self.treeview_apt_key = self.gladexml.get_widget("treeview_apt_key")
  60.     self.liststore_apt_key = gtk.ListStore(str)
  61.     self.treeview_apt_key.set_model(self.liststore_apt_key)
  62.     # Create columns and append them.
  63.     tr = gtk.CellRendererText()
  64.     tr.set_property("xpad", 10)
  65.     tr.set_property("ypad", 10)
  66.     c0 = gtk.TreeViewColumn("Key", tr, text=0)
  67.     self.treeview_apt_key.append_column(c0)
  68.     self.update_key_list()
  69.  
  70.   def on_button_apt_key_update_clicked(self, widget):
  71.       self.apt_key.update()
  72.       self.update_key_list()
  73.  
  74.   def on_button_key_add_clicked(self, widget):
  75.       chooser = gtk.FileChooserDialog(title=_("Choose a key-file"),
  76.                                       parent=self.main,
  77.                                       buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,
  78.                                                gtk.STOCK_OK,gtk.RESPONSE_ACCEPT))
  79.       res = chooser.run()
  80.       chooser.hide()
  81.       if res == gtk.RESPONSE_ACCEPT:
  82.           #print chooser.get_filename()
  83.           if not self.apt_key.add(chooser.get_filename()):
  84.               dialog_error(self.main,
  85.                     _("Error importing selected file"),
  86.                     _("The selected file may not be a GPG key file "
  87.                       "or it might be corrupt."))
  88.           self.update_key_list()
  89.           
  90.   def on_button_key_remove_clicked(self, widget):
  91.       selection = self.treeview_apt_key.get_selection()
  92.       (model,a_iter) = selection.get_selected()
  93.       if a_iter == None:
  94.           return
  95.       key = model.get_value(a_iter,0)
  96.       if not self.apt_key.rm(key[:8]):
  97.           error(self.main,
  98.                 _("Error removing the key"),
  99.                 _("The key you selected could not be removed. "
  100.                   "Please report this as a bug."))
  101.       self.update_key_list()
  102.  
  103.   def update_key_list(self):
  104.       self.liststore_apt_key.clear()
  105.       for key in self.apt_key.list():
  106.           self.liststore_apt_key.append([key])
  107.  
  108.   def run(self):
  109.       res = self.main.run()
  110.       self.main.hide()
  111.  
  112.  
  113. if __name__ == "__main__":
  114.     ui = dialog_apt_key(None)
  115.     ui.run()
  116.  
  117.